package com.db.patterns.flyweight;

import java.util.HashMap;
import java.util.Map;

//享元工厂
public class FlyweightFactory {
    private Map<String, Flyweight> flyweights = new HashMap<String, Flyweight>();

    public Flyweight getFlyweight(String key) {
        if (flyweights.containsKey(key)) {
            return flyweights.get(key);
        }
        Flyweight flyweight = new ConcreteFlyweight();
        flyweights.put(key, flyweight);
        return flyweight;
    }
}
